import { Button, Tooltip } from 'antd';
import { ColumnsRenderFun, DictionaryRenderFun } from '../../Acommon';
import { EyeOutlined } from '@ant-design/icons';
import pageStyles from '@/common/pageLayout.less';
import MyIcon from '@/components/MyIcon';
import { history } from 'umi';
import { getKeyRouter, removeDateHmsStr } from '@/utils';
import moment from 'moment';

// 资产领用表格配置
const getApplyTableColumns = () => {
  return [
    {
      title: '申请部门/单位',
      dataIndex: 'createDepartmentName',
      key: 'createDepartmentName',
      fixed: 'left',
      width: 150,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.applyInfo > b?.applyInfo ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '事项名称',
      dataIndex: 'applyTitle',
      key: 'applyTitle',
      fixed: 'left',
      width: 200,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.applyInfo > b?.applyInfo ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <a
              className={pageStyles['over-flow-hidden']}
              onClick={() => {
                history.push({
                  pathname: `/assetApplyUes/detail/{id}/{currentUserID}/:${getKeyRouter()}${getKeyRouter()}`,
                  state: {
                    pageType: 'detail',
                    record: record,
                  },
                });
              }}
            >
              {text || '--'}
            </a>
          </Tooltip>
        );
      },
    },
    {
      title: '申请人',
      dataIndex: 'createrName',
      key: 'createrName',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.createrName > b?.createrName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '申请时间',
      dataIndex: 'createTime',
      key: 'createTime',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.createTime > b.createTime ? 1 : -1),
      render: (text: string) => removeDateHmsStr(text) || '--',
    },
    {
      title: '状态',
      dataIndex: 'stateName',
      key: 'stateName',
      width: 150,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.stateName > b?.stateName ? 1 : -1),
      render: (text: number) => DictionaryRenderFun({ text, isState: true }),
    },
  ];
};

// 资产交接表格配置
const getTransferTableColumns = () => {
  return [
    {
      title: '申请部门/单位',
      dataIndex: 'createDepartmentName',
      key: 'createDepartmentName',
      fixed: 'left',
      width: 150,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.applyInfo > b?.applyInfo ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '事项名称',
      dataIndex: 'applyTitle',
      key: 'applyTitle',
      fixed: 'left',
      width: 200,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.applyInfo > b?.applyInfo ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <a
              className={pageStyles['over-flow-hidden']}
              onClick={() => {
                history.push({
                  pathname: `/assetApplyAllot/detail/{id}/{currentUserID}/:${getKeyRouter()}${getKeyRouter()}`,
                  state: {
                    pageType: 'detail',
                    record: record,
                  },
                });
              }}
            >
              {text || '--'}
            </a>
          </Tooltip>
        );
      },
    },
    {
      title: '申请人',
      dataIndex: 'createrName',
      key: 'createrName',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.createrName > b?.createrName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '申请时间',
      dataIndex: 'createTime',
      key: 'createTime',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.createTime > b.createTime ? 1 : -1),
      render: (text: string) => removeDateHmsStr(text) || '--',
    },
    {
      title: '状态',
      dataIndex: 'stateName',
      key: 'stateName',
      width: 150,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.stateName > b?.stateName ? 1 : -1),
      render: (text: number) => DictionaryRenderFun({ text, isState: true }),
    },
    {
      title: '原使用部门',
      dataIndex: 'originalDepartmentName',
      key: 'originalDepartmentName',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.originalDepartmentName > b.originalDepartmentName ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '现使用部门',
      dataIndex: 'newDepartmentName',
      key: 'newDepartmentName',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.newDepartmentName > b.newDepartmentName ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
  ];
};

// 资产退库表格配置
const getOutStoreTableColumns = () => {
  return [
    {
      title: '申请部门/单位',
      dataIndex: 'createDepartmentName',
      key: 'createDepartmentName',
      fixed: 'left',
      width: 150,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.applyInfo > b?.applyInfo ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '事项名称',
      dataIndex: 'applyTitle',
      key: 'applyTitle',
      fixed: 'left',
      width: 200,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.applyInfo > b?.applyInfo ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <a
              className={pageStyles['over-flow-hidden']}
              onClick={() => {
                history.push({
                  pathname: `/assetApplyReturn/detail/{id}/{currentUserID}/:${getKeyRouter()}${getKeyRouter()}`,
                  state: {
                    pageType: 'detail',
                    record: record,
                  },
                });
              }}
            >
              {text || '--'}
            </a>
          </Tooltip>
        );
      },
    },
    {
      title: '申请人',
      dataIndex: 'createrName',
      key: 'createrName',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.createrName > b?.createrName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '申请时间',
      dataIndex: 'createTime',
      key: 'createTime',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.createTime > b.createTime ? 1 : -1),
      render: (text: string) => removeDateHmsStr(text) || '--',
    },
    {
      title: '状态',
      dataIndex: 'stateName',
      key: 'stateName',
      width: 150,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.stateName > b?.stateName ? 1 : -1),
      render: (text: number) => DictionaryRenderFun({ text, isState: true }),
    },
  ];
};

// 资产报废表格配置
const getScrapTableColumns = () => {
  return [
    {
      title: '申请部门/单位',
      dataIndex: 'createDepartmentName',
      key: 'createDepartmentName',
      fixed: 'left',
      width: 150,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.applyInfo > b?.applyInfo ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '事项名称',
      dataIndex: 'applyTitle',
      key: 'applyTitle',
      fixed: 'left',
      width: 200,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.applyInfo > b?.applyInfo ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <a
              className={pageStyles['over-flow-hidden']}
              onClick={() => {
                history.push({
                  pathname: `/assetApplyHandle/detail/{id}/{currentUserID}/:${getKeyRouter()}${getKeyRouter()}`,
                  state: {
                    pageType: 'detail',
                    record: record,
                  },
                });
              }}
            >
              {text || '--'}
            </a>
          </Tooltip>
        );
      },
    },
    {
      title: '申请人',
      dataIndex: 'createrName',
      key: 'createrName',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.createrName > b?.createrName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '申请时间',
      dataIndex: 'createTime',
      key: 'createTime',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.createTime > b.createTime ? 1 : -1),
      render: (text: string) => removeDateHmsStr(text) || '--',
    },
    {
      title: '状态',
      dataIndex: 'stateName',
      key: 'stateName',
      width: 150,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.stateName > b?.stateName ? 1 : -1),
      render: (text: number) => DictionaryRenderFun({ text, isState: true }),
    },
  ];
};

// 资产维保表格配置
const getMaintenanceTableColumns = () => {
  return [
    {
      title: '申请部门/单位',
      dataIndex: 'createDepartmentName',
      key: 'createDepartmentName',
      fixed: 'left',
      width: 150,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.applyInfo > b?.applyInfo ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '事项名称',
      dataIndex: 'applyTitle',
      key: 'applyTitle',
      fixed: 'left',
      width: 200,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.applyInfo > b?.applyInfo ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <a
              className={pageStyles['over-flow-hidden']}
              onClick={() => {
                history.push({
                  pathname: `/assetMainten/detail/{id}/{currentUserID}/:${getKeyRouter()}${getKeyRouter()}`,
                  state: {
                    pageType: 'detail',
                    record: record,
                  },
                });
              }}
            >
              {text || '--'}
            </a>
          </Tooltip>
        );
      },
    },
    {
      title: '申请人',
      dataIndex: 'createrName',
      key: 'createrName',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.createrName > b?.createrName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '申请时间',
      dataIndex: 'createTime',
      key: 'createTime',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.createTime > b.createTime ? 1 : -1),
      render: (text: string) => removeDateHmsStr(text) || '--',
    },
    {
      title: '状态',
      dataIndex: 'stateName',
      key: 'stateName',
      width: 150,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.stateName > b?.stateName ? 1 : -1),
      render: (text: number) => DictionaryRenderFun({ text, isState: true }),
    },
    {
      title: '花费',
      dataIndex: 'spend',
      key: 'spend',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.spend > b.spend ? 1 : -1),
      render: (text: string | number) => {
        return (
          <Tooltip title={text || text == 0 ? text : '--'}>
            <div className={pageStyles['over-flow-hidden']}>{text || text == 0 ? text : '--'}</div>
          </Tooltip>
        );
      },
    },
  ];
};

// 资产变更记录表格配置
const getChangeLogTableColumns = (openEditModal) => {
  return [
    {
      title: '序号',
      dataIndex: 'index',
      key: 'index',
      visible: true,
      width: 80,
      fixed: 'left',
      render: (_: string, __: Record<string, any>, index: string) => index + 1,
    },
    {
      title: '操作部门/单位',
      dataIndex: 'createDepartmentName',
      key: 'createDepartmentName',
      fixed: 'left',
      width: 150,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.createDepartmentName > b?.createDepartmentName ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '操作人员',
      dataIndex: 'createrName',
      key: 'createrName',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.createrName > b?.createrName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '操作状态',
      dataIndex: 'status',
      key: 'status',
      width: 150,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.status > b?.status ? 1 : -1),
      render: (text: number, record: any) => {
        return (
          <>
            <Tooltip title={text === null ? '--' : text === 0 ? '正常' : '异常'}>
              <div className={pageStyles['over-flow-hidden']}>{text === null ? '--' : text === 0 ? '正常' : '异常'}</div>
            </Tooltip>
            <a
              style={{ width: 130, float: 'right' }}
              onClick={() => {
                openEditModal(record);
              }}
            >
              <MyIcon type="icon-eye" isTheme={false} />
              {'查看修改历史'}
            </a>
          </>
        );
      },
    },
    {
      title: '操作时间',
      dataIndex: 'createTime',
      key: 'createTime',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a.createTime > b.createTime ? 1 : -1),
      render: (text: string) => {
        return <Tooltip title={text}>{text ? moment(text).format('YYYY-MM-DD') : '--'}</Tooltip>;
      },
    },
  ];
};

export { getApplyTableColumns, getTransferTableColumns, getOutStoreTableColumns, getScrapTableColumns, getMaintenanceTableColumns, getChangeLogTableColumns };
